/*
 * Created by JFormDesigner on Thu Dec 01 00:09:58 ICT 2011
 */

package realestatemarketclient;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.List;
import javax.swing.table.*;
import com.jgoodies.forms.factories.*;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import com.jgoodies.forms.layout.*;
import java.sql.ResultSet;

/**
 * @author Tran Cong
 */
public class AccountingCustomerForm extends JFrame {
    public AccountingCustomerForm() {
        initComponents();
    }

    /*
     * @author Cong
     */
    
    private void loadRealType(){
        try{
            REMService.ArrayOfREALESTATETYPE type = RealEstateService.getRequest().getAllRealEstateTypes();
            List<REMService.REALESTATETYPE> lType = type.getREALESTATETYPE();
            for(REMService.REALESTATETYPE r : lType){
                comboType.addItem(r.getName());
            }
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(this, e.toString());
        }
    }
    
    private void loadTable(){
        try{
//            REMService.ArrayOfCUSTOMERREALESTATE cities = RealEstateService.getRequest().getAllCusReal();
//            DefaultTableModel dtm = new DefaultTableModel();
//            dtm.addColumn("STT");
//            dtm.addColumn("Customer Name");
//            dtm.addColumn("RealEstate Type Name");
//            int i = 1;
//            List<REMService.CUSTOMERREALESTATE> lCusRel = cities.getCUSTOMERREALESTATE();
//                for (REMService.CUSTOMERREALESTATE cr : lCusRel){  
//                    Vector v = new Vector();
//                    v.add(i++);
//                    v.add(cr.getCustomerName());
//                    v.add(cr.getRealEstateTypeName());
//                    dtm.addRow(v);
//                }
//
//                table1.setModel(dtm);
                DefaultTableModel dtm = new DefaultTableModel();
                dtm.addColumn("STT");
                dtm.addColumn("Customer Name");
                dtm.addColumn("RealEstate Type Name");
                int i = 1;
//                List<REMService.CUSTOMER> lCus = RealEstateService.getRequest().getAllCustomers().getCUSTOMER();
                List<REMService.REALESTATETYPE> re = RealEstateService.getRequest().getRealEstateTypeByCustomer(1).getREALESTATETYPE();;
//                for (REMService.CUSTOMER c : lCus){
//                    Vector v = new Vector();
//                    v.add(i++);
//                    v.add(c.getName());
//                    dtm.addRow(v);
//                }
                
                for (REMService.REALESTATETYPE r : re){
                    Vector v = new Vector();
                    v.add(i++);
                    v.add(r.getName());
                    dtm.addRow(v);
                }
                table1.setModel(dtm);
            }
        catch(Exception e){
            JOptionPane.showMessageDialog(this, e.toString());
        }
    }
    
    private void thisWindowOpened(WindowEvent e) {
        // TODO add your code here
        //loadCombobox();
        loadRealType();
    }

    private void btnOKActionPerformed(ActionEvent e) {
        // TODO add your code here
        loadTable();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - Tran Cong
        label1 = new JLabel();
        comboType = new JComboBox();
        btnOK = new JButton();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();

        //======== this ========
        setTitle("Th\u1ed1ng k\u00ea s\u1ed1 l\u01b0\u1ee3ng \u0111\u1ecba \u1ed1c");
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                thisWindowOpened(e);
            }
        });
        Container contentPane = getContentPane();
        contentPane.setLayout(new FormLayout(
            "44dlu, $lcgap, 61dlu, $lcgap, default, $lcgap, 155dlu, $lcgap, default, $lcgap, 63dlu, $lcgap, 47dlu",
            "22dlu, $lgap, fill:default, $lgap, default, $lgap, fill:133dlu, $lgap, 25dlu"));

        //---- label1 ----
        label1.setText("Lo\u1ea1i \u0111\u1ecba \u1ed1c");
        contentPane.add(label1, CC.xy(3, 3));
        contentPane.add(comboType, CC.xy(7, 3));

        //---- btnOK ----
        btnOK.setText("OK");
        btnOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                btnOKActionPerformed(e);
            }
        });
        contentPane.add(btnOK, CC.xy(11, 3));

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(table1);
        }
        contentPane.add(scrollPane1, CC.xywh(3, 7, 9, 1));
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - Tran Cong
    private JLabel label1;
    private JComboBox comboType;
    private JButton btnOK;
    private JScrollPane scrollPane1;
    private JTable table1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
